//
//  Analyzer.cpp
//  RoutingEvaluator
//
//  Created by Christopher Kemsley on 4/15/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#import <Foundation/Foundation.h>
#include "Analyzer.hpp"
#include "IAStateDefinitions.h"


NamespaceBegin



std::map<std::string,Analyzer*> const&	Analyzer :: analyzers ()
	{
	return mAnalyzers() ;
	}
Analyzer*	Analyzer :: analyzer ( std::string const& name )
	{
	std::map<std::string,Analyzer*>::iterator found = mAnalyzers() . find ( name ) ;
	if ( found == mAnalyzers().end() )
		return 0 ;
	return found->second ;
	}




Analyzer :: Analyzer ( char const* name )
	{
	mAnalyzers()[name] = this ;
	}
Analyzer :: ~Analyzer ()
	{
	
	}


std::map<std::string,Analyzer*>&	Analyzer :: mAnalyzers ()
	{
	static std::map<std::string,Analyzer*> s ;
	return s ;
	}









Output :: Output ( std::string const & basePath )
:	mBasePath	( basePath )
,	mLogOut		( (basePath+", Log.txt").c_str() , std::ios_base::out )
,	mTableOut	( (basePath+", Table.txt").c_str() , std::ios_base::out )
	{
	if ( ! mLogOut.is_open() )
		ThrowException ( "Output" , "Failed to open log output" , __FILE__,__LINE__ ) ;
	if ( ! mTableOut.is_open() )
		ThrowException ( "Output" , "Failed to open table output" , __FILE__,__LINE__ ) ;
	
	mLogOut << "Base Path: " << basePath << "\n" ;
	NSString * start = [NSString stringWithFormat:@"Run Date: %@",[NSDate date]] ;
	mLogOut << [start cStringUsingEncoding:NSASCIIStringEncoding] << "\n\n" ;
	}
Output :: ~Output ()
	{
	mLogOut.close() ;
	mTableOut.close() ;
	}


std::ostream&	Output :: logOut ()
	{
	return mLogOut ;
	}
std::ostream&	Output :: tableOut ()
	{
	return mTableOut ;
	}

void	Output :: log		( NSString * s )
	{
	mLogOut << [s cStringUsingEncoding:NSASCIIStringEncoding] << "\n" ;
	}
void	Output :: log		( NSString * format , ... )
	{
	va_list l ;
	va_start(l, format) ;
	
	NSString * s = [ [NSString alloc] initWithFormat:format arguments:l ] ;
	mLogOut << [s cStringUsingEncoding:NSASCIIStringEncoding] << "\n" ;
	
#ifndef IAIsARC
	[s release] ;
#endif
	
	va_end(l) ;
	}


void	Output :: drawNetworkTopology	( NodeSet * nodes , LinkVector const & links )
	{
		mLogOut << "This analyzer has a disabled image writer\n" ;
	}





NamespaceEnd
